<?php

namespace User\Controller;

use Think\Page;
use User\Model\ApplicationsModel;
use User\Model\FactoryModel;
use Wap\Model\StatisticsModel;

class ApplicationsController extends UserController
{
    private $_yuandan;
    private $_token;

    public function __construct()
    {
        parent::__construct();
        $this->_yuandan = -11;
        $this->_token = "iequde1415960341";
        if (!headers_sent() && // 如果页面头部信息还没有输出
            extension_loaded("zlib") && // 而且php已经加载了zlib扩展
            strstr($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip")
        ) //而且浏览器接受GZIP
        {
            ini_set('zlib.output_compression', 'On');
            ini_set('zlib.output_compression_level', '4');
        }
    }

    public function comment()
    {
        $live_comment = M("live_comment");
        $where_son1["comment_id"] = 0;
        $where_son1["msg_type"] = ApplicationsModel::TYPE_SEND;
        $where_son2["chat_id"] = 0;
        $where_son2["comment_id"] = array("neq", 0);
        $where_son2["msg_type"] = ApplicationsModel::TYPE_RECEIVE;
        $where_main['_complex'] = array(
            $where_son1,
            $where_son2,
            '_logic' => 'or'
        );
        $where_main["topic_id"] = $this->_yuandan;
        $where_main["status"] = ApplicationsModel::STATUS_ACTIVE;
        $where_main["reserve"] = $this->wxuser['token'];
        $content = I("get.content", "", "");
        if (!empty($content)) {
            $this->assign("content", $content);
//            $content = strval(json_encode($content));
//            $content = substr($content, 1, strlen($content) - 2);
//            $content_arr = explode("\u", $content);
//            foreach ($content_arr as $con){
//                if($con != ""){
//                    $content_like[] = array("LIKE", "%".$con."%");
//                    $map["content"] = array("LIKE", "%".$con."%");
//                    //$map['id'] = array(array('gt',3),array('lt',10), 'or') ;
//                }
//            }
        }
        $count = $live_comment->where($where_main)->count();
        $page = new Page($count, 15);
        $show = $page->show();

        $list = $live_comment->where($where_main)->limit($page->firstRow . "," . $page->listRows)
            ->order("id desc")->select();
        $user = $fans = array();
        if (!empty($list)) {
            foreach ($list as &$value) {
                if ($value["comment_type"] == ApplicationsModel::WISH_TXT) {
                    $value["content"] = json_decode($value["content"], true);
                } else {
                    $content = json_decode($value["content"], true);
                    $value["content"] = C("SITE_URL") . $content["media"];
                    $value["record_time"] = $content["record_time"];
                }
                $user[] = $value["openid"];
            }
            $user = array_flip(array_flip($user));
            if (!empty($user)) {
                $where_fans["openid"] = array("IN", $user);
                $where_fans["questionnaire_id"] = $this->_yuandan;
                $where_fans["status"] = ApplicationsModel::USER_ACTIVE;
                $questionnaire_fans = M("questionnaire_fans")->where($where_fans)->select();
                if (!empty($questionnaire_fans)) {
                    foreach ($questionnaire_fans as $fa) {
                        $fans[$fa["openid"]] = json_decode($fa["nickname"], true);
                    }
                }
            }
        }
        $this->assign("page", $show);
        $this->assign("list", $list);
        $this->assign("fans", $fans);
        $this->display();
    }

    public function deleteComment()
    {
        $id = I("get.id", -1, "");
        $where['id'] = $id;
        $updated = M("live_comment")->where($where)->save(array("status" => ApplicationsModel::STATUS_DELETE));
        //删除扩散的数据
        $where_send['chat_id'] = $id;
        $updated_send = M("live_comment")->where($where_send)->save(array("status" => ApplicationsModel::STATUS_DELETE));
        if ($updated !== false) {
            $this->success("删除成功", "", true);
        } else {
            $this->success("删除失败", "", true);
        }
    }

    public function deleteComments()
    {
        $ids = I("get.ids", "", "");
        if (!empty($ids)) {
            $ids = explode('|', $ids);
        }
        $where['id'] = array('IN', $ids);
        $updated = M("live_comment")->where($where)->save(array('status' => ApplicationsModel::STATUS_DELETE));
        $where_send['chat_id'] = array('IN', $ids);
        $updated_send = M("live_comment")->where($where_send)->save(array('status' => ApplicationsModel::STATUS_DELETE));
        if ($updated !== false) {
            $this->success("删除成功", "", true);
        } else {
            $this->error("删除失败", "", true);
        }
    }

    public function user()
    {
        if ($this->wxuser['token'] == $this->_token) {
            $questionnaire_fans = M("questionnaire_fans");
            $where["questionnaire_id"] = $this->_yuandan;
            $where["status"] = ApplicationsModel::USER_ACTIVE;
            $nickname = I("get.nickname", "", "");
            if (!empty($nickname)) {
                $where["nickname"] = array("LIKE", "%" . $nickname . "%");
                $this->assign("nickname", $nickname);
            }
            $count = $questionnaire_fans->where($where)->count();
            $page = new Page($count, 15);
            $show = $page->show();

            $list = $questionnaire_fans->where($where)->limit($page->firstRow . "," . $page->listRows)
                ->order("id desc")->select();
            if (!empty($list)) {
                foreach ($list as &$value) {
                    $value["nickname"] = json_decode($value["nickname"], true);
                }
            }
            $this->assign("page", $show);
            $this->assign("list", $list);
        }
        $this->display();
    }

    public function deleteUser()
    {
        $where['id'] = I("get.id", -1, "");
        $updated = M("questionnaire_fans")->where($where)->save(array("status" => ApplicationsModel::USER_DELETE));
        if ($updated !== false) {
            $this->success("删除成功", "", true);
        } else {
            $this->success("删除失败", "", true);
        }
    }

    public function deleteUsers()
    {
        $ids = I("get.ids", "", "");
        if (!empty($ids)) {
            $ids = explode('|', $ids);
        }
        $where['id'] = array('IN', $ids);
        $updated = M("questionnaire_fans")->where($where)->save(array('status' => ApplicationsModel::USER_DELETE));
        if ($updated !== false) {
            $this->success("删除成功", "", true);
        } else {
            $this->error("删除失败", "", true);
        }
    }

    public function user_detail()
    {
        $uid = I("get.uid", -1, "");
        $type = I("get.type", -1, "");
        $live_comment = M("live_comment");
        $where_user["id"] = $uid;
        $self_user = M("questionnaire_fans")->where($where_user)->find();
        $nickname = "";
        if (!empty($self_user)) {
            $nickname = json_decode($self_user["nickname"], true);
        }
        if ($type == ApplicationsModel::TYPE_RECEIVE) {
            $where["comment_id"] = $uid;
            $where["msg_type"] = $type;
        } else {
            $where_son1["openid"] = $self_user["openid"];
            $where_son1["msg_type"] = ApplicationsModel::TYPE_SEND;
            $where_son2["openid"] = $self_user["openid"];
            $where_son2["msg_type"] = ApplicationsModel::TYPE_RECEIVE;
            $where_son2["comment_id"] = array("neq", 0);
            $where['_complex'] = array(
                $where_son1,
                $where_son2,
                '_logic' => 'or'
            );
        }
        $where["topic_id"] = $this->_yuandan;
        $where["status"] = ApplicationsModel::STATUS_ACTIVE;
        $where["reserve"] = $this->wxuser['token'];

        $count = $live_comment->where($where)->count();
        $page = new Page($count, 15);
        $show = $page->show();

        $list = $live_comment->where($where)->limit($page->firstRow . "," . $page->listRows)->order("id desc")
            ->select();
        $user = $fans = array();
        if (!empty($list)) {
            foreach ($list as &$value) {
                if ($value["comment_type"] == ApplicationsModel::WISH_TXT) {
                    $value["content"] = json_decode($value["content"], true);
                } else {
                    $content = json_decode($value["content"], true);
                    $value["content"] = C("SITE_URL") . $content["media"];
                    $value["record_time"] = $content["record_time"];
                }
                $user[] = $value["openid"];
            }
            $user = array_flip(array_flip($user));
            if (!empty($user)) {
                $where_fans["openid"] = array("IN", $user);
                $where_fans["questionnaire_id"] = $this->_yuandan;
                $where_fans["status"] = ApplicationsModel::USER_ACTIVE;
                $questionnaire_fans = M("questionnaire_fans")->where($where_fans)->select();
                if (!empty($questionnaire_fans)) {
                    foreach ($questionnaire_fans as $fa) {
                        $fans[$fa["openid"]] = json_decode($fa["nickname"], true);
                    }
                }
            }
        }
        $this->assign("nickname", $nickname);
        $this->assign("page", $show);
        $this->assign("list", $list);
        $this->assign("fans", $fans);
        $this->assign("uid", $uid);
        $this->assign("type", $type);
        $this->display();
    }

    public function statistics()
    {
        if ($this->wxuser['token'] == $this->_token) {
            $params = I("get.", "", "");
            $cond['topic_id'] = 1;
            $date = array("start_date" => "", "end_date" => "");

            if (empty($params['start_date'])) {
                $date['start_date'] = date("Y-m-d", strtotime("-7 days"));
            } else {
                $date['start_date'] = $params['start_date'];
            }

            if (empty($params['end_date'])) {
                $date['end_date'] = date("Y-m-d");
            } else {
                $date['end_date'] = $params['end_date'];
            }
            $cond['date'] = array("BETWEEN", array($date['start_date'], $date['end_date']));
            $cond['api'] = "yuandan";
            $statistics = M("statistics")->where($cond)->getField('date, pv_num, uv_num');
            $statistics_dates = $statistics_pv = $statistics_uv = array();
            foreach ($statistics as $val) {
                $statistics_dates[] = $val['date'];
                $statistics_pv[] = $val['pv_num'];
                $statistics_uv[] = $val['uv_num'];
            }
            if (date("Y-m-d") >= $date['start_date'] && date("Y-m-d") <= $date['end_date']) {
                if ($statistics_dates && ($statistics_dates[sizeof($statistics_dates) - 1] == date("Y-m-d"))) {
                    $yuandan_data = S("yuandan");
                    if (isset($yuandan_data[1])) {
                        $statistics_pv[sizeof($statistics_dates) - 1] = $statistics_pv[sizeof($statistics_dates) - 1]
                            + $yuandan_data[1]['pv'];
                        $statistics_uv[sizeof($statistics_dates) - 1] = $statistics_uv[sizeof($statistics_dates) - 1]
                            + $yuandan_data[1]['uv'];
                    }
                } else {
                    $today_pv = 0;
                    $today_uv = 0;
                    $yuandan_data = S("yuandan");
                    if (isset($yuandan_data[1])) {
                        $today_pv = $yuandan_data[1]['pv'];
                        $today_uv = $yuandan_data[1]['uv'];
                    }
                    $statistics_dates[] = date("Y-m-d");
                    $statistics_pv[] = $today_pv;
                    $statistics_uv[] = $today_uv;
                }
            }
            $this->assign('dates', json_encode($statistics_dates));
            $this->assign('pv', json_encode($statistics_pv));
            $this->assign('uv', json_encode($statistics_uv));
        }
        $this->display();
    }

    //---安全举报开始----
    public function tip()
    {
        $cond['status'] = array("NEQ", 9);
        $cond['type'] = 1;
        $count = M("tip")->where($cond)->count();
        $page = new Page($count, 15);
        $show = $page->show();

        $list = M("tip")->where($cond)->limit($page->firstRow . "," . $page->listRows)
            ->order("tip_id desc")->select();
        $this->assign("page", $show);
        $this->assign("list", $list);
        $this->display();
    }

    public function exportTip()
    {
        set_time_limit(0);
        vendor('phpexcel.PHPExcel');
        $objExcel = new \PHPExcel();
        $objActSheet = $objExcel->getActiveSheet();
        $objActSheet->getColumnDimension('A')->setWidth(50);
        $objActSheet->getColumnDimension('B')->setWidth(50);
        $objActSheet->getColumnDimension('C')->setWidth(30);
        $objActSheet->getColumnDimension('D')->setWidth(30);
        $objActSheet->getColumnDimension('E')->setWidth(30);
        $objActSheet->getColumnDimension('F')->setWidth(30);
        $objActSheet->setCellValue('A1', "举报内容");
        $objActSheet->setCellValue('B1', "单位");
        $objActSheet->setCellValue('C1', "姓名");
        $objActSheet->setCellValue('D1', "电话");
        $objActSheet->setCellValue('E1', "图片");
        $objActSheet->setCellValue('F1', "举报时间");
        $line = 2;
        $cond['status'] = array("NEQ", 9);
        $cond['type'] = 1;
        $count = M("tip")->where($cond)->count();
        if ($count > 0) {
            $limit = $count / 100;
            for ($i = 0; $i < $limit; $i++) {
                $start = $i * 100;
                $tips = M("tip")->where($cond)->limit($start, 100)->order("tip_id desc")->select();
                foreach ($tips as $tip) {
                    $objActSheet->getRowDimension($line)->setRowHeight(120);
                    $objActSheet->setCellValue('A' . $line, $tip['content']);
                    $objActSheet->setCellValue('B' . $line, $tip['company']);
                    $objActSheet->setCellValue('C' . $line, $tip['name']);
                    $objActSheet->setCellValue('D' . $line, $tip['telephone']);
                    $img = @imagecreatefromjpeg(C("SITE_URL") . $tip['pic']);
                    if (!$img) {
                        $img = @imagecreatefrompng(C("SITE_URL") . $tip['pic']);
                    }
                    if ($img) {
                        $objDrawing = new \PHPExcel_Worksheet_MemoryDrawing();
                        $objDrawing->setImageResource($img);
                        $objDrawing->setHeight(120);
                        $objDrawing->setWidth(120);
                        $objDrawing->setCoordinates('E' . $line);
                        $objDrawing->setOffsetX(10);
                        $objDrawing->setRenderingFunction(\PHPExcel_Worksheet_MemoryDrawing::RENDERING_DEFAULT);
                        $objDrawing->setMimeType(\PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT);
                        $objDrawing->setWorksheet($objActSheet);
                    } else {
                        $objActSheet->setCellValue('E' . $line, '');
                    }
                    $objActSheet->setCellValue('F' . $line, $tip['created_time']);
                    $line++;
                }
            }
        }
        $fileName = '安全举报' . date('Ymd') . '.xlsx';
        header('Content-Type: application/vnd.ms-excel');
        header("Content-Disposition: attachment;filename=\"$fileName\"");
        header('Cache-Control: max-age=0');
        $objWriter = new \PHPExcel_Writer_Excel2007($objExcel);
        $objWriter->save('php://output');
    }

    public function delete_tip()
    {
        $cond['tip_id'] = I("get.id", "", "");
        $data['status'] = 9;
        if (!empty($cond['tip_id'])) {
            M("tip")->where($cond)->save($data);
        }
        $this->ajaxReturn("成功");
    }
    //---安全举报结束----

    //-----民意直通车开始----
    public function suggest()
    {
        $cond['status'] = array("NEQ", 9);
        $cond['type'] = 2;
        $count = M("tip")->where($cond)->count();
        $page = new Page($count, 15);
        $show = $page->show();

        $list = M("tip")->where($cond)->limit($page->firstRow . "," . $page->listRows)
            ->order("tip_id desc")->select();
        $this->assign("page", $show);
        $this->assign("list", $list);
        $this->display();
    }

    public function exportSuggest()
    {
        set_time_limit(0);
        vendor('phpexcel.PHPExcel');
        $objExcel = new \PHPExcel();
        $objActSheet = $objExcel->getActiveSheet();
        $objActSheet->getColumnDimension('A')->setWidth(50);
        $objActSheet->getColumnDimension('B')->setWidth(50);
        $objActSheet->getColumnDimension('C')->setWidth(30);
        $objActSheet->getColumnDimension('D')->setWidth(30);
        $objActSheet->getColumnDimension('E')->setWidth(30);
        $objActSheet->getColumnDimension('F')->setWidth(30);
        $objActSheet->setCellValue('A1', "举报内容");
        $objActSheet->setCellValue('B1', "单位");
        $objActSheet->setCellValue('C1', "姓名");
        $objActSheet->setCellValue('D1', "电话");
        $objActSheet->setCellValue('E1', "图片");
        $objActSheet->setCellValue('F1', "举报时间");
        $line = 2;
        $cond['status'] = array("NEQ", 9);
        $cond['type'] = 2;
        $count = M("tip")->where($cond)->count();
        if ($count > 0) {
            $limit = $count / 100;
            for ($i = 0; $i < $limit; $i++) {
                $start = $i * 100;
                $tips = M("tip")->where($cond)->limit($start, 100)->order("tip_id desc")->select();
                foreach ($tips as $tip) {
                    $objActSheet->getRowDimension($line)->setRowHeight(120);
                    $objActSheet->setCellValue('A' . $line, $tip['content']);
                    $objActSheet->setCellValue('B' . $line, $tip['company']);
                    $objActSheet->setCellValue('C' . $line, $tip['name']);
                    $objActSheet->setCellValue('D' . $line, $tip['telephone']);
                    $img = @imagecreatefromjpeg(C("SITE_URL") . $tip['pic']);
                    if (!$img) {
                        $img = @imagecreatefrompng(C("SITE_URL") . $tip['pic']);
                    }
                    if ($img) {
                        $objDrawing = new \PHPExcel_Worksheet_MemoryDrawing();
                        $objDrawing->setImageResource($img);
                        $objDrawing->setHeight(120);
                        $objDrawing->setWidth(120);
                        $objDrawing->setCoordinates('E' . $line);
                        $objDrawing->setOffsetX(10);
                        $objDrawing->setRenderingFunction(\PHPExcel_Worksheet_MemoryDrawing::RENDERING_DEFAULT);
                        $objDrawing->setMimeType(\PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT);
                        $objDrawing->setWorksheet($objActSheet);
                    } else {
                        $objActSheet->setCellValue('E' . $line, '');
                    }
                    $objActSheet->setCellValue('F' . $line, $tip['created_time']);
                    $line++;
                }
            }
        }
        $fileName = '安全举报' . date('Ymd') . '.xlsx';
        header('Content-Type: application/vnd.ms-excel');
        header("Content-Disposition: attachment;filename=\"$fileName\"");
        header('Cache-Control: max-age=0');
        $objWriter = new \PHPExcel_Writer_Excel2007($objExcel);
        $objWriter->save('php://output');
    }
    //-----民意直通车结束----
    //------------------------------------------选择题工具开始----------------------------------------------------
    public function select()
    {
        $cond['status'] = array("NEQ", 9);
        $cond['token'] = $this->wxuser['token'];

        $count = M("tool_ans")->where($cond)->count();

        $page = new Page($count, 10);
        $show = $page->show();
        $this->assign("page", $show);

        $list = M("tool_ans")->where($cond)->limit($page->firstRow . ',' . $page->listRows)->order('id desc')->select();
        $this->assign("list", $list);
        $this->display();
    }

    public function selectAdd()
    {
        $params = I("post.", "", "");
        if (empty($params)) {
            $type = 'add';
            $this->assign('type', $type);
            return $this->display('selectDetail');
        }
        if (empty($params['name'])) {
            return $this->my_error("请填写名称");
        }
        $data['name'] = $params['name'];
        $data['desc'] = $params['desc'];
        $data['a_name'] = $params['a_name'];
        $data['b_name'] = $params['b_name'];
        $data['token'] = $this->wxuser['token'];
        $data['status'] = 0;//--待激活--
        M("tool_ans")->add($data);
        return $this->my_success("成功");
    }

    public function selectUpdate()
    {
        $type = I("get.type", "", "");
        $id = I("get.id", "", "");
        $params = I("post.", "", "");
        if ($type == 'update' && empty($params)) {
            $tool_ans = M("tool_ans")->where(['id' => $id])->find();
            $this->assign("tool_ans", $tool_ans);
            return $this->display("selectDetail");
        }
        $id = I("post.id", "", "");
        if (empty($id)) {
            return $this->my_error("信息有误");
        }
        $data['name'] = $params['name'];
        $data['desc'] = $params['desc'];
        $data['a_name'] = $params['a_name'];
        $data['b_name'] = $params['b_name'];
        M("tool_ans")->where(['id' => $id])->save($data);
        return $this->my_success("成功");
    }

    public function delete()
    {
        $id = I("get.id", "", "");
        $name = I("get.name", "", "");
        $data['status'] = 9;//--删除---
        if (!empty($id)) {
            M($name)->where(['id' => $id])->save($data);
        }
        return $this->my_success("成功");
    }

    public function pass()
    {
        $id = I("get.id", "", "");
        $name = I("get.name", "", "");
        $data['status'] = 1;//--正常---
        if (!empty($id)) {
            M($name)->where(['id' => $id])->save($data);
        }
        return $this->my_success("成功");
    }

    public function unpass()
    {
        $id = I("get.id", "", "");
        $name = I("get.name", "", "");
        $data['status'] = 0;//----待激活---
        if (!empty($id)) {
            M($name)->where(['id' => $id])->save($data);
        }
        return $this->my_success("成功");
    }

    public function selectShare()
    {
        $params = I('post.', '', '');
        if (empty($params)) {
            $id = I('get.id', '', '');
            if (empty($id)) {
                return $this->redirect('/User/Applications/select');
            }
            $tool_ans = M("tool_ans")->where(['id' => $id])->find();
            if (empty($tool_ans)) {
                return $this->redirect('/User/Applications/select');
            }
            $this->assign('tool_ans', $tool_ans);
            return $this->display();
        } else {
            if (!empty($params['id'])) {
                $data['share_title'] = $params['share_title'];
                $data['share_desc'] = $params['share_desc'];

                $img = $params['share_pic'];
                if (!empty($img)) {
                    $ajaxImg = FactoryModel::ajaxImgUpload($img, "tool_ans");
                    if ($ajaxImg['code'] != 1) {
                        return $this->my_error('图片上传失败');
                    }
                    $data['share_pic'] = $ajaxImg['msg'];
                }
                M("tool_ans")->where(['id' => $params['id']])->save($data);
            }
            return $this->my_success("成功");
        }
    }
    //------------------------------------------选择题工具结束----------------------------------------------------
    //-------------数据统计开始-------------------
    public function data()
    {
        set_time_limit(0);
        $cond['status'] = array("NEQ", 9);
        $year = I("get.year", "", "");
        if (!empty($year)) {
            $startdate = strtotime($year . '-01-01 00:00:00');
            $enddate = strtotime($year . '-12-31 23:59:59');
            $cond['startdate'] = array("between", $startdate . "," . $enddate);
        }
        $praise_list = M("praise")->where($cond)->getField("id,title,token");
        foreach ($praise_list as $id => &$praise) {
            $cond_praise_item['status'] = array("NEQ", -1);
            $cond_praise_item['praise_id'] = $id;
            $praise['votes'] = M("praise_item")->where($cond_praise_item)->sum("votes");

            $cond_praise_record['praise'] = $id;
            $praise['record'] = M("praise_record2")->where($cond_praise_record)->count("DISTINCT openid");
        }
        $this->assign("praise_list", $praise_list);
        $this->display();
    }
    //-------------数据统计结束-------------------
    //-------信息广订单列表开始---------
    public function xxfl()
    {
        $cond['status'] = array("NEQ", 9);
        $params = I("get.", "", "");
        if (!empty($params['start_date']) && !empty($params['end_date'])) {
            $cond['create_date'] = array("BETWEEN", array($params['start_date'], $params['end_date']));
        } elseif (!empty($params['start_date'])) {
            $cond['create_date'] = array("GT", $params['start_date']);
        } elseif (!empty($params['end_date'])) {
            $cond['create_date'] = array("LT", $params['end_date']);
        }
        if ($params['status'] == 1) {
            $cond['status'] = 0;
        } elseif ($params['status'] == 2) {
            $cond['status'] = 1;
        }
        if (!empty($params['phone'])) {
            $cond['phone'] = $params['phone'];
        }
        $count = M("xxfl_order")->where($cond)->count();

        $page = new Page($count, 10);
        $show = $page->show();
        $this->assign("page", $show);

        $list = M("xxfl_order")->where($cond)->limit($page->firstRow . ',' . $page->listRows)->order('id desc')->select();
        $this->assign("list", $list);
        $this->display();
    }

    public function exportXxfl()
    {
        set_time_limit(0);
        vendor('phpexcel.PHPExcel');
        $objExcel = new \PHPExcel();
        $objActSheet = $objExcel->getActiveSheet();
        $objActSheet->setCellValue('A1', "名称");
        $objActSheet->setCellValue('B1', "电话");
        $objActSheet->setCellValue('C1', "联系地址");
        $objActSheet->setCellValue('D1', "个人/公司");
        $objActSheet->setCellValue('E1', "广告类型");
        $objActSheet->setCellValue('F1', "广告内容");
        $objActSheet->setCellValue('G1', "提交时间");
        $objActSheet->setCellValue('H1', "配送方式");
        $line = 2;
        $params = I("get.", "", "");
        $cond['status'] = array("NEQ", 9);
        if (!empty($params['start_date']) && !empty($params['end_date'])) {
            $cond['create_date'] = array("BETWEEN", array($params['start_date'], $params['end_date']));
        } elseif (!empty($params['start_date'])) {
            $cond['create_date'] = array("GT", $params['start_date']);
        } elseif (!empty($params['end_date'])) {
            $cond['create_date'] = array("LT", $params['end_date']);
        }
        if ($params['status'] == 1) {
            $cond['status'] = 0;
        } elseif ($params['status'] == 2) {
            $cond['status'] = 1;
        }
        if (!empty($params['phone'])) {
            $cond['phone'] = $params['phone'];
        }
        $count = M("xxfl_order")->where($cond)->count();
        if ($count > 0) {
            $limit = $count / 100;
            for ($i = 0; $i < $limit; $i++) {
                $start = $i * 100;
                $dtls = M("xxfl_order")->where($cond)->limit($start, 100)->order("id desc")->select();
                foreach ($dtls as $dtl) {
                    $objActSheet->setCellValue('A' . $line, $dtl['name']);
                    $objActSheet->setCellValue('B' . $line, $dtl['phone']);
                    $objActSheet->setCellValue('C' . $line, $dtl['address']);
                    if($dtl['type'] == 0){
                        $objActSheet->setCellValue('D' . $line, "公司");
                    }else{
                        $objActSheet->setCellValue('D' . $line, "个人");
                    }
                    $type_detail = ApplicationsModel::getAdName($dtl['typed']);
                    $objActSheet->setCellValue('E' . $line, $type_detail);
                    $objActSheet->setCellValue('F' . $line, $dtl['desc']);
                    $objActSheet->setCellValue('G' . $line, $dtl['create_date']);
                    if($dtl['delivery'] == 0){
                        $objActSheet->setCellValue('H' . $line, "快递");
                    }else{
                        $objActSheet->setCellValue('H' . $line, "自取");
                    }
                    $line++;
                }
            }
        }
        $data['status'] = 1;
        M("xxfl_order")->where($cond)->save($data);
        $fileName = '信息分类' . date('Ymd') . '.xlsx';
        header('Content-Type: application/vnd.ms-excel');
        header("Content-Disposition: attachment;filename=\"$fileName\"");
        header('Cache-Control: max-age=0');
        $objWriter = new \PHPExcel_Writer_Excel2007($objExcel);
        $objWriter->save('php://output');
    }
    //-------信息广订单列表结束---------
}